<?php
require_once "opsdbconn.php";

$flag=0;


//全部
$sql = "SELECT CONCAT(0 + sum(amount)) as value from o_order WHERE id in(SELECT oo.id FROM o_order oo LEFT JOIN o_order_list ool ON ool.order_id = oo.id WHERE ( oo.STATUS = 7 OR oo.`status` = 2 OR oo.`status` = 3 OR oo.`status` = 4 OR oo.`status` = 5) and oo.shop_name ='诚美家具旗舰店' GROUP BY ool.order_id )";


$query=$mysqli->query($sql);
$res=mysqli_fetch_array($query);



//今天
$sql1 = "select sum(amount)  as value from o_order where  date_format(pay_time,'%Y-%m-%d')=date_format(now(),'%Y-%m-%d') and shop_name ='诚美家具旗舰店' and  ( status=7 or `status`=2 or `status`=3 or `status`=4 or `status`=5 ) ";


$query1=$mysqli->query($sql1);
$res1=mysqli_fetch_array($query1);

//昨天
$sql2 = "select sum(amount)  as value from o_order where  date_format(pay_time,'%Y-%m-%d')= date_format(date_sub(now(),interval 1 day),'%Y-%m-%d')  and shop_name ='诚美家具旗舰店'  and  ( status=7 or  `status`=2 or `status`=3 or `status`=4 or `status`=5 ) ";

$query2=$mysqli->query($sql2);
$res2=mysqli_fetch_array($query2);



$jsonStr["all"] = number_format($res['value'],2);
$jsonStr["today"] = number_format($res1['value'],2);
$jsonStr["yesterday"] = number_format($res2['value'],2);
 

$sqltoptkje="SELECT * from (SELECT shop_name,sum(amount) as am from o_order where to_days(pay_time) = to_days(now()) and shop_name ='诚美家具旗舰店' and  `status`=8 GROUP BY shop_name) as p ";

$querytkje=$mysqli->query($sqltoptkje);
$restkje=mysqli_fetch_array($querytkje);


//刷单金额
$jsonStr["sdje"]=0;


if($restkje['am']!=null){
	//退款金额
	$jsonStr["tkje"]=number_format($restkje['am'],2);
}else{
	$jsonStr["tkje"]=0.00;
}



$sqltop11="SELECT shop_name,sum(amount) as am from o_order where to_days(pay_time) = to_days(now()) and shop_name ='诚美家具旗舰店' and ( status=7 or  `status`=2 or `status`=3 or `status`=4 or `status`=5 )";

$querytop11=$mysqli->query($sqltop11);
$restop11=mysqli_fetch_array($querytop11);






$sqltop10="SELECT shop_name,count(1) as sl,sum(amount) as am from o_order where date_format(pay_time,'%Y-%m')=date_format(now(),'%Y-%m') and shop_name ='诚美家具旗舰店' and ( status=7 or  `status`=2 or `status`=3 or `status`=4 or `status`=5 )";
$querytop10=$mysqli->query($sqltop10);
$restop10=mysqli_fetch_array($querytop10);

$jsonStr['shoplist'][1]['name']=$restop10['shop_name'];
$jsonStr['shoplist'][1]['ddsl']=number_format($restop10['sl'],0);
$jsonStr['shoplist'][1]['sdje']=0;



if($restkje['am']!=null){
	//退款金额
	

	$jsonStr['shoplist'][1]['tkje']=$restkje['am'];
}else{
	$jsonStr['shoplist'][1]['tkje']=0.00;
}

$jsonStr['shoplist'][1]['xsmb']=number_format(100000,2);


$jsonStr['shoplist'][1]['jdt']=round(($restop10['am']/100000)*100,0);


$jsonStr['shoplist'][1]['jrxse']=number_format($restop11['am'],2);

$jsonStr['shoplist'][1]['dqxse']=number_format($restop10['am'],2);






mysqli_close($mysqli); 

echo jsonSuccess($jsonStr);

?>